package com.demo.common.permission.login;

import com.demo.common.vo.Result;
import com.demo.entity.SysUser;
import com.demo.service.SysUserService;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.Valid;

@RestController
@RequestMapping("/user")
public class LoginController {

    @Resource
    private SysUserService sysUserService;

    /**
     * 用户登录
     * @param sysUser
     * @return
     */
    @PostMapping("/login")
    public Result login(@RequestBody @Valid SysUser sysUser){
        String token = sysUserService.login(sysUser);
        return Result.success(token);
    }

    /**
     * 退出登录
     * @return
     */
    @PostMapping("/logout")
    public Result logout(){
        sysUserService.logout();
        return Result.success();
    }

}
